--[[ Heavily modified; based on (?)Kogitsune's chatcommand system.]]--
-- Holy shit I just realized I still had this file after 9 months. After 2 minutes I fixed it. It's usable now :P


local ChatPrefix = "!"		-- When you create a chat command, what should the prefix be to identify it?


-- Idea: put true/false boolean after func in the Add function, true for creating a concommand too, false for not. if they did not specify, it's false.

if not SERVER then return; end

local table = table;
local string = string;
local unpack = unpack;
local hook = hook;

module "chatcommand"	-- Ignore this part.


local ChatCommands = {};	-- Chat command table - holds all chatcommand information.
function Add( name, func )	-- the chatcommand creation function.

	local lowername = string.lower( name );	-- lowering the string.
	
	ChatCommands[ ChatPrefix .. lowername ] = func	-- create chatcommand.
	
end
function Remove( name )	-- the chatcommand remove function.

	local lowername = string.lower( name );	-- lowering the string.
	
	ChatCommands[ ChatPrefix .. lowername ] = nil	-- remove chatcommand by calling the string nil.
	
end

function Exists( name ) -- chatcommand function to check if a chatcommand is valid.

	local lowername = string.lower( name );	-- lowering the string
	
	return ChatCommands[ ChatPrefix .. lowername ] != nil -- checking if the string is in the table, and if it's not nil
	
end

function GetList()	-- get the table information.

	return ChatCommands;	-- return the table, which holds the information.
	
end

local function Lusion_ChatCommands( ply, text, toall )

	local lowertext = string.lower( text )
	local explode = string.Explode( " ", lowertext )
	local func = ChatCommands[ explode[1] ]; 
	
	if ( func ) then    

		table.remove( explode, 1 )
		func( ply, explode[1], unpack( explode ) )  -- Runs the command function 
		return ""  	-- Doesn't say anything in chat.
		
	end
	
	return text
	
end
hook.Add( "PlayerSay", "Lusion_ChatCommands", Lusion_ChatCommands)